/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaSwitch.java
 *
 * Created on 31/01/2012, 13:43:40
 */
package tsb.UI.Ventanas;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import tsb.dominio.dispositivos.Dispositivo;
import tsb.dominio.dispositivos.coneccion.Switch;
import tsb.dominio.excepciones.MACException;
import tsb.dominio.interfaces.IP;
import tsb.dominio.interfaces.InterfaceDeConeccion;
import tsb.dominio.interfaces.MAC;
import tsb.dominio.interfaces.RJ45FastEthernet;

/**
 *
 * @author Fede
 */
public class VentanaSwitch extends javax.swing.JFrame
{
    private Switch sw;
    private ArrayList<InterfaceDeConeccion> listaInterfaces;
    private tsb.gestores.GestorDeDispositivos gestorDisp;
    private tsb.UI.PanelArrastrar.BotonPersonalizado btnPersonalizado;

    public VentanaSwitch(String nombreAMostrar,tsb.gestores.GestorDeDispositivos gestorDisp,Dispositivo disp,tsb.UI.PanelArrastrar.BotonPersonalizado btnPersonalizado) throws MACException
    {
        initComponents();
        this.setLocationRelativeTo(null);
        sw=(Switch)disp;
        this.setTitle(sw.getNombreAMostrar());
        this.gestorDisp=gestorDisp;
        this.btnPersonalizado=btnPersonalizado;

        this.panelSwitch.setNombreAMostrar(sw.getNombreAMostrar());
        this.panelSwitch.setEncendido(sw.getEstado());

        //this.panelSwitch.fede();

        this.setSwitc(sw);


    }

    public void setSwitc(Switch sw)
    {
        this.sw=sw;
        this.panelSwitch.setNombreAMostrar(sw.getNombreAMostrar());
        this.panelSwitch.setEncendido(sw.getEstado());
        this.panelSwitch.setInterfaces(this.sw.getInterfaces());

    }
    public Switch getSwitch() throws MACException
    {
        this.sw.setNombreAMostrar(this.panelSwitch.getNombreAMostrar());
        this.sw.setEstado(this.panelSwitch.getEncendido());
        this.sw.setInterfaces(this.panelSwitch.getInterfacesUpdate(this.sw.getInterfaces()));

        return sw;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelBotones = new javax.swing.JPanel();
        btnCancelar = new javax.swing.JButton();
        btnAceptar = new javax.swing.JButton();
        panelSwitch = new tsb.UI.Paneles.PanelSwitch();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Switch");

        panelBotones.setBackground(new java.awt.Color(255, 255, 255));

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelBotonesLayout = new javax.swing.GroupLayout(panelBotones);
        panelBotones.setLayout(panelBotonesLayout);
        panelBotonesLayout.setHorizontalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotonesLayout.createSequentialGroup()
                .addContainerGap(263, Short.MAX_VALUE)
                .addComponent(btnAceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar)
                .addContainerGap())
        );
        panelBotonesLayout.setVerticalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotonesLayout.createSequentialGroup()
                .addContainerGap(13, Short.MAX_VALUE)
                .addGroup(panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnAceptar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelSwitch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelBotones, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(panelSwitch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.dispose();
}//GEN-LAST:event_btnCancelarActionPerformed

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        try {
            agregarDisp();
        } catch (MACException ex) {
            Logger.getLogger(VentanaSwitch.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_btnAceptarActionPerformed
    private void agregarDisp() throws MACException
    {
         Switch sw= this.getSwitch();
         
         btnPersonalizado.setText(sw.getNombreAMostrar());
         this.btnPersonalizado.setVentanaAbierta(false);
         gestorDisp.actualizarDisp(sw);
         this.dispose();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JPanel panelBotones;
    private tsb.UI.Paneles.PanelSwitch panelSwitch;
    // End of variables declaration//GEN-END:variables
}
